@extends('Admin.layouts.application')
@section('css')
    <link rel="stylesheet" href="/assets/xSystem/vendor/daterangepicker/daterangepicker.css">

@endsection
@section('content')
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">入住用户</strong> /
                    <small>Occupancy user</small>
                </div>
            </div>

            <hr>
            @include('Admin.layouts._flash')
            <div class="am-g" style="height: 37px;">
                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a type="button" class="am-btn am-btn-success" href="{{url('member/create')}}">
                                <span class="am-icon-plus"></span> 新增
                            </a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">

                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-id">编号</th>
                                <th class="table-thumb">入住用户</th>
                                <th class="table-title">房间号</th>
                                <th class="table-thumb">性别</th>
                                <th class="table-thumb">入住时间</th>
                                <th class="table-title">排序</th>
                                <th class="table-title">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($members as $member)
                                <tr data-id="{{$member->id}}" id="row_{{$member->id}}" class="xParent">
                                    <td>{{$member->id}}</td>

                                    <td>
                                        {{$member->username}}
                                    </td>
                                    <td>
                                        {{$member->room->room}}
                                    </td>
                                    <td>
                                        {{show_sex($member->sex)}}
                                    </td>
                                    <td>
                                        {{$member->created_at}}
                                    </td>
                                    <td class="am-hide-sm-only">
                                        <input  type="text" name="sort_order" class="am-input-sm"
                                                value="{{$member->sort_order}}">
                                    </td>

                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                                   href="{{route('member.edit', $member->id)}}">
                                                    <span class="am-icon-pencil-square-o"></span> 编辑
                                                </a>

                                                <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                                   href="{{route('member.destroy', $member->id)}}"
                                                   data-method="delete"
                                                   data-token="{{csrf_token()}}" data-confirm="确认退房吗?">
                                                    <span class="am-icon-trash-o"></span> 退房
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                        共{{$members->total()}}条记录
                        <div class="am-cf">
                            <div class="am-fr">
                                {!! $members->appends(Request::all())->links() !!}
                            </div>
                        </div>
                        <hr/>
                    </form>
                </div>
            </div>
        </div>
        @include('Admin.layouts._footer')

    </div>
@endsection

@section('js')

    <script src="/assets/xSystem/vendor/daterangepicker/moment.js"></script>
    <script src="/assets/xSystem/vendor/moment/locale/zh-cn.js"></script>
    <script src="/assets/xSystem/vendor/daterangepicker/daterangepicker.js"></script>

    <script src="/assets/xSystem/js/daterange_config.js"></script>
    <script>
        $(function () {


            //排序
            $("input[name='sort_order']").change(function () {
                var data = {
                    sort_order: $(this).val(),
                    id: $(this).parents("tr").data('id')
                };
                console.log(data);
                $.ajax({
                    type: "PATCH",
                    url: "/member/sort_order",
                    data: data,
                });
            });

        });
    </script>
@endsection





